<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */


/**
 * Backend IndexController
 *
 * @author	Martin Hesse <info@mh-dev.de>
 * @package	MH-Dev.-Board
 */
class Backend_IndexController extends Zend_Controller_Action
{
	private $registry; // registry
	private $auth; // user-values
	private $settings; // board-settings
	private $baseUrl; // helper
	
	/*
	 * Init class vars and stuff
	 */
	public function init()
	{		
		// registry
		$this->registry = Zend_Registry::getInstance();
		
		// settings
		$this->settings	= $this->registry->get('settings');
		
		// helper
		$baseUrl		= new MHDEV_View_Helper_BaseUrl();
		$this->baseUrl	= $baseUrl->BaseUrl();
		
		// auth
		$auth = Zend_Auth::getInstance();
		$this->view->auth = $auth->hasIdentity();
    	
		if($auth->hasIdentity())
		{
			$this->view->auth_role 			= $auth->getIdentity()->role;
			$this->view->username 			= $auth->getIdentity()->username;
			$this->view->auth_uid			= $auth->getIdentity()->uid;
			$this->view->unread_messages	= $auth->getIdentity()->count_unread_messages;
		}
		else
		{
			$this->view->username 	= $this->registry->get('lang')->_('guest');
		}

		$this->auth = $auth;
    	
		// lang
		$this->view->translate = $this->registry->get('lang');
		
		// include js
		$this->view->headScript()->appendFile($this->baseUrl . '/static/js/jquery-1.3.2.min.js');
		$this->view->headScript()->appendFile($this->baseUrl . '/static/js/backend.js');
		$this->view->headLink()->appendStylesheet($this->baseUrl . '/static/css/default/jquery.css');
		$this->view->headScript()->appendFile($this->baseUrl . '/static/js/jquery-ui-1.7.2.custom.min.js');
	}
	
	
	
	/*
	 * Shows some information and this stuff ...
	 */
	public function indexAction()
	{
		// helper
		$baseurl	= new MHDEV_View_Helper_BaseUrl();
		
        /*
         * Get latest log entries
         */
		
		// handle file
        $log_file 	= '../application/data/log_' . date('Y-m-d', time());

        if($handle = fopen($log_file, 'r'))
        {
			// init array
			$logArray	= array();
			
			$log_count = 0;
			if($log_count<=11)
			{
				while(($content = fgetcsv ($handle, 1000, ";")) !== FALSE ) 
				{
					$logArray[$log_count]['timestamp']	= $content[0];
					$logArray[$log_count]['level']		= $content[1];
					$logArray[$log_count]['level_id']	= $content[2];
					$logArray[$log_count]['desc']		= $content[3];
					$log_count++;
				}
			}
			
			$this->view->logCon 	= $logArray;
			$this->view->logSum		= $log_count;
        }	
	}
}